package net.googlecode.exigenlab.task5;

import java.util.ArrayList;

import net.googlecode.exigenlab.task5.personal.Boss;
import net.googlecode.exigenlab.task5.personal.Employee;
import net.googlecode.exigenlab.task5.personal.Manager;
import net.googlecode.exigenlab.task5.personal.Worker;
import net.googlecode.exigenlab.task5.salary.SalaryCalculator;
import net.googlecode.exigenlab.task5.sorting.SortingTools;

/**
 * Class for testing task#3. Create instances of all realized classes and check
 * their work.
 * 
 * @author Poddybniak Petr <a href="mailto:PPoddybniak@gmail.com">Poddybniak
 *         Petr</a>
 * @since 14.04.2011
 */
public class SalaryApp {
	public static ArrayList<Worker> testWorkerList = new ArrayList<Worker>();
	private SalaryCalculator cal = new SalaryCalculator();

	/**
	 * Default constructor.
	 * 
	 */
	public SalaryApp() {

	}

	/**
	 * Calculate workers salary.
	 * 
	 * @param args
	 *            arguments of command line
	 */
	public static void main(String[] args) {
		SalaryApp sal = new SalaryApp();
		SortingTools testSortingTools = new SortingTools();
		testWorkerList.add(sal.createBoss());
		testWorkerList.add(sal.createEmployeeWithBonus());
		testWorkerList.add(sal.createEmployeeWithoutBonus());
		testWorkerList.add(sal.createManagerWithBonus());
		testWorkerList.add(sal.createManagerWithoutBonus());
		testWorkerList.add(sal.createEmployeeWithoutBonus2());
		if (args.length > 0) {
			if (args[0].equals("code")) {
				testSortingTools.idSortedWorkers(testWorkerList);
			} else {
				if (args[0].equals("name")) {
					testSortingTools.nameSortedWorkers(testWorkerList);
				} else {
					if (args[0].equals("salary")) {
						testSortingTools.salarySortedWorkers(testWorkerList);
					}
				}
			}
		} else {
			System.out
					.println("Wrong parameters. Please enter new parameters.");
		}
	}

	/**
	 * Create manager without bonus.
	 * 
	 * @return Manager without bonus.
	 */
	public Manager createManagerWithoutBonus() {
		Manager manager = new Manager("Ivan", "Ivanov", "003");
		manager.setAge(30);
		manager.setPerHour(true);
		manager.setBonus(false);
		manager.setRate(25);
		cal.calcSalary(manager);

		return manager;
	}

	/**
	 * Create manager with bonus.
	 * 
	 * @return Manager with bonus.
	 */
	public Manager createManagerWithBonus() {
		Manager manager = new Manager("Petr", "Petrov", "005");
		manager.setAge(35);
		manager.setBonus(true);
		manager.setBonusAmount(1000);
		manager.setPerHour(false);
		manager.setRate(5000);
		cal.calcSalary(manager);

		return manager;
	}

	/**
	 * Create employee with bonus.
	 * 
	 * @return Employee with bonus.
	 */
	public Employee createEmployeeWithBonus() {
		Employee employee = new Employee("Semen", "Semenov", "009");
		employee.setAge(55);
		employee.setBonus(true);
		employee.setBonusAmount(1500);
		employee.setPerHour(true);
		employee.setRate(8);
		cal.calcSalary(employee);
		return employee;
	}

	/**
	 * Create employee without bonus.
	 * 
	 * @return Employee without bonus.
	 */
	public Employee createEmployeeWithoutBonus() {
		Employee employee = new Employee("Sergey", "Sergeev", "011");
		employee.setAge(45);
		employee.setBonus(false);
		employee.setPerHour(false);
		employee.setExperience(15);
		employee.setRate(200);

		cal.calcSalary(employee);
		return employee;
	}

	/**
	 * Create employee without bonus #2.
	 * 
	 * @return Employee without bonus.
	 */
	public Employee createEmployeeWithoutBonus2() {
		Employee employee = new Employee("Andrey", "Andreev", "007");
		employee.setAge(45);
		employee.setBonus(false);
		employee.setPerHour(false);
		employee.setExperience(15);
		employee.setRate(200);

		cal.calcSalary(employee);
		return employee;
	}

	/**
	 * Create boss.
	 * 
	 * @return Boss with bonus.
	 */
	public Boss createBoss() {
		Boss boss = new Boss("Pankrat", "Pankratovich", "001");
		boss.setAge(55);
		boss.setRate(35);
		boss.setBonusAmount(2000);

		cal.calcSalary(boss);
		return boss;
	}
}
